package ipcards;

import ipcards.events.*;
import ipcards.net.Connection;


/**
 * Used by other classes to perform player actions
 * Probably almost redundant, but might take a bit of effort to merge with Player
 */
public class PlayerModel implements PlayerActionPerformer {
	
	public Connection connection;
	public Controller controller;
	public Room room;
	
	
	public PlayerModel(Connection connection, Controller controller) {
		this.controller = controller;
		this.room = controller.getRoom();
		this.connection = connection;	
	}
	

	/**
	 * Called when a PlayerAction is fired. 
	 * Sends PlayerActions to either the GUI or the server depending on the action.
	 */
	public void performPlayerAction(PlayerAction pa) {
		int action = pa.getAction();
		
		//Local PlayerActions
		if (action == PlayerAction.SELECTION_ADD || 
			action == PlayerAction.SELECTION_REMOVE) {
			
			room.localPlayer.performPlayerAction(pa);
		}
		
		//Remote PlayerActions (sent to server)
		else {
			connection.performPlayerAction(pa);
		}
	}
}